/***************************************************************************
 创建者: 华磊
 开始时间: 2018.8.14
 copyright: (C) 华友高科
 修改说明: (每次有修改就添加一条，带有 修改人，修改时间，修改描述)
 example (1) hualei 2017.5.8 类的具体实现代码编写

 ***************************************************************************
 *  @file x.h
 *  功能:
 *
 *                                                                         *
 ***************************************************************************/
#ifndef CANIODRIVER_H
#define CANIODRIVER_H
#include <qvector.h>
#include <qmap.h>
#include "canioconfig.h"
#include "canbusdevicedriver.h"

/**
 * @brief The CanIoDriver class 驱动类
 */
class CanIoDriver
{
public:
    CanIoDriver(QString configFileNameIn,int aliasIn, int busNumberIn, int deviceIdIn,
                CanbusDeviceDriver *canbusDriverIn);
    ~CanIoDriver();

public:
    int startPdoMode();
    int sendIoDataRequestCommand();//not used

    int updateData();
    int getDeviceAddressInfo(int& aliasOut, int& busNumberOut, int& deviceIdOut);
    int getVendorId();

    int readDi(QVector<bool> & diReturn);
    int readAi(QVector<double> & aiReturn);
    int readAllDi(QVector<bool> & diReturn);
    int readAllAi(QVector<double> & aiReturn);
    int readDo(QVector<bool> & doReturn);
    int writeDo(QVector<bool> doValue, QVector<double> aoValue);
    bool isInitialOkStatus();
    int getDiDoCount(int &diCounter,int &doCounter,int &aiCounter, int &aoCounter);

private:
    int writeDo_shanghaiWeiqun(QVector<bool> doValue);
    int processDataFrame_shanghaiWeiqun(QVector<bool> & diReturn,QVector<bool> & doReturn);

    int writeDo_shengzhengpuzhong(QVector<bool> doValue, QVector<double> aoValue);
    int processDataFrame_shengzhengpuzhong(QVector<bool> & diReturn, QVector<short> &aiValue);

    int initial(QString fileName);

public:
    int alias;
    int busNumber;
    int deviceId;

private:
    CanIoConfig *canioConfig;
    CanbusDeviceDriver *canbusDriver;
    bool isInitialedOk;
    IoModuleRegAddressInfo regAdd;
    E_VENDOR_ID vendorId;

    int diCount;
    int doCount;
    int aiCount;
    int aoCount;

    QVector<bool> diValue_device;
    QVector<bool> doValue_device;

    QVector<short> aiValue_device;
    QVector<short> aoValue_device;

    int diNoReceiveCount;
    int doNoReceiveCount;


};

#endif // CANIODRIVER_H
